package com.jamu.mbok;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

public class LoadingScreen extends Activity{
	
	AnimationDrawable animLoader;
	ImageView imgLoader;
	final int animTime = 40;
	boolean isRunning = true;
	static Thread t;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.loadscreen);
        imgLoader = (ImageView)findViewById(R.id.image_loader);
        animLoader = (AnimationDrawable)imgLoader.getDrawable();
        t = new Thread(){
        	public void run(){
        		try {
        			int i=1;
        			while(isRunning&&i<animTime){
        				i++;
        				sleep(100);
        			}
        			nextAct();
        			isRunning=false;
        		} catch (InterruptedException e) {
					e.printStackTrace();
				}
        	}
        };
        t.start();
    }
    @Override
    public void onWindowFocusChanged (boolean hasFocus){
    	animLoader.start();
    }
    
    public void nextAct(){
		this.startActivity(new Intent("android.intent.action.HOMESCREEN"));
		overridePendingTransition(R.anim.fade, R.anim.hold);
		this.finish();
    }
}
